package com.example.administrator.zyfypt_104ytr.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.zyfypt_104ytr.R;
import com.example.administrator.zyfypt_104ytr.activity.CActivity;
import com.example.administrator.zyfypt_104ytr.activity.FocusActivity;

import static android.content.Context.MODE_PRIVATE;


/**
 * Created by Neusoft on 2017/4/9.
 */

  public class Fragment6 extends Fragment {
                private  TextView tvinfo,tvusername;
                private View view=null;
                private Context context;
                private Button btn,button8,button9;
    private SharedPreferences sp;
    private String username;
                @Nullable
                @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            context=getActivity();
            //动态加载Fragment1的布局文件
            view=inflater.inflate(R.layout.fragment6,container,false);
            //获取布局上的控件，注意通过view获取
            tvinfo=(TextView)view.findViewById(R.id.textView8);
                    tvusername=(TextView)view.findViewById(R.id.textView7);
            btn=(Button)view.findViewById(R.id.button7);
                    button8=(Button)view.findViewById(R.id.button8);
                    button9=(Button)view.findViewById(R.id.button9);
            tvinfo.setText("我的个人信息");
                    button9.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            switch (v.getId()){
                                case R.id.button9:
                                    Intent intent=new Intent(getActivity(),CActivity.class);//forward为当前activity，forwardTarget为新的activity
                                    startActivity(intent);
                                    break;
                            }
                        }
                    });
                    button8.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            switch (v.getId()){
                                case R.id.button8:
                                    Intent intent=new Intent(getActivity(), FocusActivity.class);
                                    startActivity(intent);
                                    break;
                            }
                        }
                    });
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    switch (v.getId()){
                        case R.id.button7:
                            getActivity().onBackPressed();
                            break;
                    }
                }
            });
                    sp=context.getSharedPreferences("login",MODE_PRIVATE);
                    readSP();
                    tvusername.setText(username);
            //注意Toast第一个参数上下文
            Toast.makeText(context, "加载Fragment我", Toast.LENGTH_SHORT).show();
            //返回动态生成的view
            return view;
        }
    private void readSP() {
        username = sp.getString("username", null);
    }
}

